//
//  SearchDetailViewController.m
//  Protect -A
//
//  Created by 付剑英 on 16/6/30.
//  Copyright © 2016年 付剑英. All rights reserved.
//

#import "SearchDetailViewController.h"
#import "APPTools.h"
#import "baseTableview.h"
#import "SearchTableViewCell.h"
@interface SearchDetailViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,retain)NSMutableDictionary *dic;
@property (nonatomic,retain)baseTableview *table;
@end

@implementation SearchDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self handleData];
    [self createTableView];
    // Do any additional setup after loading the view.
}


#pragma mark - ------------ 解析数据---------------

-(void)handleData{

    NSString *temp = @"http://www.duitang.com/napi/blog/detail/?__dtac=%257B%2522_r%2522%253A%2520%2522203659%2522%257D&app_code=gandalf&app_version=5.8%20rv%3A149591&blog_id=512642603&device_name=iPhone%205&device_platform=iPhone5%2C2&include_fields=tags%2Crelated_albums%2Crelated_albums.covers%2Croot_album%2Cshare_links_2%2Cextra_html%2Ctop_comments%2Ctop_like_users&locale=zh_CN&platform_name=iPhone%20OS&platform_version=9.2&screen_height=568&screen_width=320&top_comments_count=12&top_forward_users_count=8&top_like_users_count=8";
    NSString *url = [temp stringByReplacingOccurrencesOfString:@"512642603" withString:_strDetail];
  
    [APPTools GETWithURL:url par:nil success:^(id responseObject) {
        
        self.dic = [NSMutableDictionary dictionary];
        self.dic = responseObject[@"data"];
        
        [_table reloadData];
        
        
    } filed:^(NSError *error) {
      
        
    }];

}
#pragma mark - ------------ 创建控件 ---------------

-(void)createTableView{
   
    self.table = [[baseTableview alloc]initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
    self.table.delegate = self;
    self.table.dataSource = self;
    [self.view addSubview:self.table];
    
    [self.table registerClass:[SearchTableViewCell class] forCellReuseIdentifier:@"pool"];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return 1 ;

}
#pragma mark - ------------ Cell 赋值 ---------------

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    SearchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"pool"];
    cell.dic = _dic;
    return cell;

}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    if (_dic) {
  //        返回图片高 + 文字 + 其他控件的高度
        CGFloat photo =  [ SearchTableViewCell heightWithPhoto:_dic[@"photo"][@"width"]  height:_dic[@"photo"][@"height"] ];
        CGFloat text = [SearchTableViewCell heightWithText:_dic[@"msg"]];
        return photo + text +111;
    }
    return 0;
}













- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
